function psdData = GET_SensitivityPSDData(obj, isotope, varargin)
%GET_SENSITIVITYPSDDATA Summary of this function goes here
%   Detailed explanation goes here
    switch isotope
        case '129'
            ch = obj.controller.PIDSettings.Xe129Lock.index;
            [center, pVal, iVal, dVal, DlimVal, rateVal, filterOrder, filterBW] = obj.controller.getXe129LockingParameter();
        case '131'
            ch = obj.controller.PIDSettings.Xe131Lock.index;
            [center, pVal, iVal, dVal, DlimVal, rateVal, filterOrder, filterBW] = obj.controller.getXe131LockingParameter();
        otherwise
            error('Wrong isotope. Isotope must be either "129" or "131". ');
    end

    p=inputParser();
    p.addParameter('center', center, @isscalar);
    p.addParameter('pValue', pVal, @isscalar);
    p.addParameter('iValue', iVal, @isscalar);
    p.addParameter('dValue', dVal, @isscalar);
    p.addParameter('dLim', DlimVal, @isscalar);
    p.addParameter('rate', rateVal, @isscalar);
    p.addParameter('order', filterOrder, @isscalar);
    p.addParameter('bandwidth', filterBW, @isscalar);
    p.addParameter('name', 'PIDShiftFFT', @ischar);
    
    p.addParameter('average', 100, @(x) isscalar(x) && x >= 1);
    p.addParameter('maxFrequency', 100, @(x) isscalar(x) && x >= 0);
    p.addParameter('pointNumber', 65536, @(x) isscalar(x) && x >= 0);
    p.parse(varargin{:});
    
    pid.pValue = p.Results.pValue; 
    pid.iValue = p.Results.iValue; 
    pid.dValue = p.Results.dValue;
    pid.order = p.Results.order;
    pid.bandwidth = p.Results.bandwidth;
    
    switch isotope
        case '129'
            obj.controller.lockXe129Frequency(pid);
        case '131'
            obj.controller.lockXe131Frequency(pid);
    end
    
    
    %%
    spect = obj.controller.ziSlave.spectrumModule();
    spect.setControl('grid_repetitions', p.Results.average);
    spect.setParam('spectrum/frequencyspan', p.Results.maxFrequency);
    spect.setParam('grid/cols', p.Results.pointNumber);

    spect.reset();
    spect.subscribeChannel(ch, 'stream/shift.val.fft.abs.avg', 'channel_name', 'pids');
    psdData= spect.run();
    spect.unsubscribeChannel();
    
    spect.addToSession(p.Results.name);
%     MeasurementSession.save( session.close() );
end

